#!/bin/bash
SVNSERVER=$1
PROJECT=$2
FOLDER=$3
VERSION=$4
OPERATOR=$5
echo build normal maven bxn project
echo server:$SVNSERVER project:$PROJECT
echo folder:$FOLDER version:$VERSION
CURRENTTIME=$6
TODAY=$(date +%Y%m%d)
echo timestamp:$CURRENTTIME 
BASE=/tmp/package/$PROJECT-$CURRENTTIME
echo base:$BASE
rm -rf $BASE
svn export svn://$SVNSERVER/$PROJECT/$FOLDER/$VERSION $BASE --username tiger --password svn555666
cd $BASE
sed -i '8c <version>'$VERSION'</version>' pom.xml
mvn package -Dmaven.test.skip
WAR=$(ls target | grep .war)
echo $WAR
unzip target/$WAR -d target/temp
touch manifest
echo Manifest-Version: $VERSION >>manifest
echo Created-By: $OPERATOR >>manifest
jar cvfm  target/temp/WEB-INF/lib/$PROJECT-$VERSION.jar manifest -C target/temp/WEB-INF/classes/ .
rm -rf target/temp/WEB-INF/classes
mkdir dist
cd target/temp
zip -r ../../dist/$PROJECT.war *
cd ../..
mkdir dist/install
cp -r doc dist/install/doc
cp -r script dist/install/script
cd dist
zip -r $PROJECT-$VERSION.zip *
mkdir /opt/build/$TODAY
cp $PROJECT-$VERSION.zip /opt/build/$TODAY/$PROJECT-$VERSION-$CURRENTTIME-$OPERATOR.zip
cd ../..
rm -rf $BASE

